package leetcode.周赛.第245场;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2021/6/13 11:25
 * @description：https://leetcode-cn.com/problems/merge-triplets-to-form-target-triplet/
 */
public class 第3题_合并若干三元组以形成目标三元组 {

    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.mergeTriplets(new int[][]{{1,3,1}}, new int[]{1,3,2}));
    }


    class Solution {
        public boolean mergeTriplets(int[][] triplets, int[] target) {
            int[] best = new int[3];
            for (int[] triplet : triplets) {
                boolean ok = true;
                for (int i = 0; i < 3; i++) {
                    if (triplet[i] > target[i]) {
                        ok = false;
                    }
                }
                if (!ok) continue;
                for (int i = 0; i < 3; i++) {
                    best[i] = Math.max(best[i], triplet[i]);
                }
            }
            for (int i = 0; i < 3; i++) {
                if (best[i] != target[i]) return false;
            }
            return true;
        }

    }
}
